#include "NetSession.h"

namespace mp_net
{
	NetSession::NetSession(
		shpSocket socket, shpIoService service)
	{
		while(!TryLock()){;;}
		m_sockets = new shpSocket(socket);
		m_socketCount = 1;
		m_ioService = service;
		m_thread.reset();
		Unlock();
	}

	void NetSession::ThreadInitialization()
	{

	}

	void NetSession::ThreadUpdate()
	{
		try
		{
			while(!TryLock()){;;}
			//Poll the IO Service
			m_ioService->poll();
			Unlock();
		} 
		catch(boost::exception const& ex)
		{
			throw "boost poll exception.";
		}
		catch(std::exception const& ex)
		{
			throw "std boost poll exception.";
		}
		Sleep(1);
	}

	void NetSession::ThreadShutdown()
	{

	}
}